package com.kd.service.recruiter.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kd.bean.recruiter.Company_msg;
import com.kd.bean.recruiter.Recruiter_basic;
import com.kd.dao.recruiter.ICompany_msgDao;
import com.kd.dao.recruiter.IRecruiter_basicDao;
import com.kd.dao.recruiter.IRecruitment_msgDao;
import com.kd.service.recruiter.ICompany_msgService;

@Service
@Transactional
public class Company_msgServiceImpl implements ICompany_msgService{
	
	@Autowired
	private ICompany_msgDao comDao;
	
	@Autowired
	private IRecruitment_msgDao msgDao;
	
	@Autowired
	private IRecruiter_basicDao basicDao;

	@Override
	public Company_msg queryByCompany_id(Integer company_id) throws Exception {
		
		return comDao.queryByCompany_id(company_id);
	}

	@Override
	public Boolean updateCompanyMsg(Company_msg company,Recruiter_basic basic) throws Exception {
		Boolean flag = comDao.updateCompanyMsg(company)>0;
		if(flag) {
			//修改招聘信息 rec_company_name,rec_company_address 招聘者旗下的所有招聘信息
			msgDao.updateRec_company_nameAndRec_company_address(company.getCompany_name(), company.getCompany_address(), basic.getRecruiter_id());
		}
		return flag;
	}

	@Override
	public Boolean insertCompanyMsg(Company_msg company,Recruiter_basic basic) throws Exception {
		Boolean flag = comDao.insertCompanyMsg(company)>0;
		if(flag) {
			//判断是否绑定公司
			if(basic.getCompany_id()==null) {
				Company_msg comMsg = comDao.queryByCompanyMsgByCompany_name(company.getCompany_name());
				basicDao.updateBasicOfCompany(comMsg.getCompany_id(), basic.getRecruiter_id());
			}
		}
		return flag;
	}

}
